package Utils;

import Beans.Inventory;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import io.restassured.response.Response;

import static io.restassured.RestAssured.given;

public class Actions extends BasicTest {
    String URL="";
    //根据门店编码和商品编码取供货关系
    public void sku_sup_Relationship(String sitecode,String skucode){


    }

    public  Inventory queryInventory(String sitecode, String skucode){
        Inventory inventory=new Inventory();
        Response response=given()
                .contentType("application/json")
                .headers("x-yh-wms-whid","170952316587872256")
                .cookies(cookies)
                .body("{\"pagesize\":50,\"pageindex\":1,\"sitecode\":\""+sitecode+"\",\"skucode\":\""+skucode+"\"}")
                .post(URL+"site-inventory-center/siteinventory/list");
        JSONObject json = JSONObject.parseObject(response.asString());
        //System.out.println(json);
        Object qtyonhand= JSONPath.eval(json,"data.rows[0].qtyonhand");
        Object qtyobdalloc=JSONPath.eval(json,"data.rows[0].qtyobdalloc");
        Object qtyfrozen=JSONPath.eval(json,"data.rows[0].qtyfrozen");
        Object qtyintransitdoc=JSONPath.eval(json,"data.rows[0].qtyintransitdoc");
        Object qtyintransit=JSONPath.eval(json,"data.rows[0].qtyintransit");


        inventory.setQtyfrozen(Double.valueOf(qtyfrozen.toString()));
        inventory.setQtyintransit(Double.valueOf(qtyintransit.toString()) );
        inventory.setQtyintransitdoc(Double.valueOf(qtyintransitdoc.toString()) );
        inventory.setQtyobdalloc(Double.valueOf(qtyobdalloc.toString()) );
        inventory.setQtyonhand(Double.valueOf(qtyonhand.toString()) );
        inventory.setSitecode(sitecode);
        inventory.setSkucode(skucode);

        return inventory;
    }


}
